package com.jielihaofeng.nettyadvance.chat.config;

import com.jielihaofeng.nettyadvance.chat.protocol.Serializer;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author Johnnie Wind
 * @description 配置文件
 * @date 2021/11/18 17:59
 */
public class Config {

    static Properties properties;

    static {
        try (InputStream in = Config.class.getResourceAsStream("/application.properties")) {
            properties = new Properties();
            properties.load(in);
        } catch (IOException e) {
            throw new ExceptionInInitializerError(e);
        }
    }

    public static Serializer.SerializerAlgorithm getSerializerAlgorithm() {
        // 获取配置文件的配置 serializer.algorithm
        String algo = properties.getProperty("serializer.algorithm");
        // 没有配置，默认使用JDK序列化
        if (algo == null) {
            return Serializer.SerializerAlgorithm.Java;
        } else {
            return Serializer.SerializerAlgorithm.valueOf(algo);
        }
    }

}
